package com.crowd.web.controller;

import com.crowd.entity.Admin;
import com.crowd.entity.Student;
import com.crowd.service.api.IAdminService;
import com.crowd.util.ResultEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author Stone
 * @date 2020/5/8 16:47
 */
@Controller
public class TestController {
    @Autowired
    private IAdminService adminService;

    public Logger logger = LoggerFactory.getLogger(AdminController.class);
    @RequestMapping("/hello")
    public String hello(Model model){
        List<Admin> adminList = adminService.findAll();
        model.addAttribute(adminList);
        return "/hello";
    }

    @RequestMapping("/sendBtn1")
    public void test1(@RequestParam("array[]")List<Integer> list){
        for (Integer number:list) {
            logger.info("number"+number);
        }
    }

    @RequestMapping("/sendbtn2")
    @ResponseBody
    public String test2(@RequestBody List<Integer> list){
        for (Integer number:list) {
            logger.info("number:"+number);
        }
        return "success";
    }

    @RequestMapping("/sendbtn3")
    @ResponseBody
    public ResultEntity<Student> test3(@RequestBody Student student){
        logger.info(student.toString());
        ResultEntity<Student> resultEntity = ResultEntity.successWithData(student);
        return  resultEntity;
    }
}
